export function findMatchedRoute(routes, pathname) {
  console.log(routes, pathname);
  try {
    for (let i = 0; i < routes.length; i++) {
      const route = routes[i];
      if (route?.redirect) continue;

      //以 / 进行分割
      let route_path = route?.path?.split("/").filter((item) => item);
      let path_name = pathname?.split("/").filter((item) => item);

      if (route?.path === "/" && route?.children) {
        return findMatchedRoute(route.children, pathname);
      }
      // 检查每个路径部分是否匹配
      if (route_path)
        for (let key of route_path) {
          if (key) {
            if (path_name.includes(key) && route.children) {
              return findMatchedRoute(route.children, pathname);
            } else if (path_name.includes(key)) {
              if (path_name.length > 2) {
                //处理编辑操作
                return routes[i + 1];
              }
              return route;
            }
          }
        }
    }
    return {}; //null
  } catch (error) {
    return {};
  }
}
